package com.tnovoselec.android.travelassistant.view;

import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nth.android.image.ImageDownloader;
import com.tnovoselec.android.travelassistant.R;
import com.tnovoselec.android.travelassistant.Util;
import com.tnovoselec.android.travelassistant.dto.ForecastFavoritesDto;

/**
 * Title: Android Framework - Meteo <br />
 * <br />
 * Copyright: Copyright (c) 2011 <br />
 * <br />
 * NTH Company: NTH d.o.o. <br />
 * <br />
 * 
 * HomeFeatureLayout class is used to show weather forecast in horizontal
 * scrollview which scrolls in discrete motion.
 * 
 * @author Tomislav Novoselec
 * @version 1.0.0
 * @since 1.0.0
 * 
 */
public class HomeFeatureLayout extends LinearLayout {

//	private static final int SWIPE_MIN_DISTANCE = 5;
	//private static final int SWIPE_THRESHOLD_VELOCITY = 300;

	ArrayList<ForecastFavoritesDto> mItems = null;
	int mActiveFeature = 0;
	private ImageDownloader downloader;
	private Context context;

	public HomeFeatureLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	public HomeFeatureLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public HomeFeatureLayout(Context context) {
		super(context);
		init(context);
	}

	private void init(Context context) {
		downloader = ImageDownloader.getInstance();
		this.context = context;
	}

	/**
	 * Method which is used to tell HorizontalLayout which items need to be put
	 * in ScrollView
	 * 
	 * @param items
	 */
	public void setFeatureItems(ArrayList<ForecastFavoritesDto> items) {
		LinearLayout internalWrapper = (LinearLayout) this.findViewById(R.id.meteo_horizontal_container);
		internalWrapper.removeAllViews();

		final String degreeString = context.getString(R.string.meteo_temperature_degree);

		this.mItems = items;
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1);
		for (int i = 1; i < items.size(); i++) {
			ForecastFavoritesDto f = items.get(i);
			View v = View.inflate(this.getContext(), R.layout.meteo_forecast_indicator, null);
			((TextView) v.findViewById(R.id.meteo_forecast_day)).setText(Util.daysOfWeek.get(f.getDayOfWeekString().toLowerCase()));
			((TextView) v.findViewById(R.id.meteo_forecast_temp)).setText(f.getTemperatureLow() + degreeString + "/" + f.getTemperatureHigh() + degreeString);
			downloader.download(f.getIconUrl(), ((ImageView) v.findViewById(R.id.meteo_image)), true);
			internalWrapper.addView(v, params);
		}

	}

}
